AppTitle "Celestial Rift - Version 1.1 (C)2001 Myke P" ;what this program will be called in MICROSOFT WINDOWS.
;This makes two CONSTants. These are values which will NOT change at any point in the program, so we set their values now.
Const SCREEN_WIDTH = 800
Const SCREEN_HEIGHT = 600
;This is the code which tells Blitz what Display Resolution to use on the Graphics Card. The "GRAPHICS" command should always be placed before you do
;*anything* image-related in your program
Graphics SCREEN_WIDTH,SCREEN_HEIGHT,0,1 ;start the graphics mode at SCREEN_WIDTH by SCREEN_HEIGHT, let Blitz choose the depth (,0) and run full screen (,1)
;more program CONSTants..
Const GAME_AREA_X = 50000 ;these two set the size of the map. You *should* keep them the same, 'cos the radar is square
Const GAME_AREA_Y = 50000 ;but technically, you can change the values to anything you like! ;)
;the following constants are keyboard "SCAN" codes. Every key on the keyboard has a number. You can get the full list in your Blitz manual.
Const KEY_CLOCKWISE = 25 ;(p)
Const KEY_ANTICWISE = 24 ;(o)
Const KEY_SPEEDUP = 16 ;(q)
Const KEY_SPEEDDOWN = 30 ;(a)
Const KEY_FIRE = 57 ;(Space)
Const KEY_QUIT = 1 ;(Escape)
Const KEY_PAUSE = 7 ;(Number 6 on the main keyboard)
Const KEY_DEBUG = 59 ;(F1)
Const KEY_SAVESCREEN = 88 ;(F12)
;the following constants affect the way the game plays. Feel free to mess with the values..
Const INCR_ROTATE# = 5 ;.. but DON'T touch this, otherwise the game will crash (I only drew the animation frames for 5 degree intervals!)
Const INCR_SPEED# = 0.5
Const INCR_SLOW# = 0.125
Const SPEED_MAX = 25
Const SPEED_MIN = -5
;set up changable variables for game/menu (with initial values, if you like - i.e.: you could just as soon as set them later!)
Global FLAG_GAMEON = 1
Global FLAG_PAUSE
Global FLAG_SAVESCREEN = 0
Global FLAG_DEBUG = 0
Global FLAG_GAMESTARTER
Global PLAYER_SHIELD#
Global PLAYER_SPEED#
Global PLAYER_ANGLE#
Global PLAYER_X#
Global PLAYER_Y#
Global timer
Global frames
Global starson
Global game_pause_frame
Global game_accept_pause
Global game_pause_stat
;a "#" symbol after the variable name means it can hold a FLOATING POINT number, i.e.: 190.1234
;without the "#" symbol, the variable is, by default, an INTEGER (Whole) number, i.e.: 190
;use the symbols when you are *sure* that you want it to hold specific types of data:
;# - floating point
;% - integer (whole number)
;$ - string (text, i.e.: "MYKE 12345"
Global tempstr$
timer = CreateTimer(50) ;create a timer set at 50ms (game speed) - play with this to see how you can increase or decrease the speed of the game.
;this should be set at a speed which will look near enough the same on *every* PC it will be played on.
;My PC (a 733MHz PIII with an nVidia GeForce card) will handle upwards of 150 frames per second, quite happily
;but 'lesser' machines will not. 50, therefore, is quite sensible For a game of this nature, who's minimum system spec
;will be something like a PII 300MHz machine (i.e.: Blitz Basic's minimum spec!)
;NOTE: there's no need to organise your variable declarations, as I have here, into sections. They can appear in any order you like, before the main program begins.
;I just do this, 'cos it looks right professional! :))))
;picture/animation (and related) variables
Dim game_stars(5) ;these 3 are ARRAYS. An array is automatically Global, but requires the Keyword (Yellow bit) DIM instead. This means "Dimension".
Global game_player
Global game_player_frame
Global game_gameover
Global game_paused
;Types are like Structures in C. You have a "Type" called whatever. Then you can make multiple versions of the type. Each version of the Type has the same properties, i.e.:
;a FISH (the Type) has EYES, MOUTH, SCALES And FINS (it's properties) - ALL FISH have these properties.
;a DOG (the Type) has EYES, MOUTH, FUR and TAIL (it's properties) - ALL DOGS have these properties (look like this.)
Type stars ;create "Type" for parallex stars
Field depth,x#,y# ;each star has a depth, x and y position
End Type
menustars = SCREEN_HEIGHT/3 ;generate a number of stars, so that they look dense enough on all test resolutions
starson = 1 ;tells the program to show the stars (see later)
For i=0 To menustars ;create <menustars> number of stars in the STARS type
star.stars=New stars ;add a new star for each increment of i
Next
;this code loads the image numbers into an array called "game_ stars", which we DIMmed earlier. It has 6 containers (0,1,2,3,4,5) but I'm only using 1 to 5!
;an "image number" is what Blitz uses to reference graphics held in the Video Memory, i.e.:
;1. Image number 12 is a picture of a flower.
;2. Make a variable called "flower_pic" = 12
;3. Wherever Blitz is told to draw "flower_pic", reference image number 12 in the Video Memory.
game_stars(1) = LoadImage("GfxRes/backg-star-1.bmp") ;container (1) in "game_stars" holds the image number for this picture ("GfxRes/backg-star-1.bmp")
;the following text will only be printed on the screen while the "FLAG_DEBUG" variable is set to 1 (which for the purpose of this tutorial, we've left it at!)
If FLAG_DEBUG = 1 Then
;the TEXT command writes a STRING of text onto the screen at the given coordinates in the currently set font
;as I haven't used the LoadFont or SetFont commands, this will just be Blitz' default font.
Color 255,255,255 ;just in case, set the colo(u)r of the text to WHITE (255, 255, 255)
Text 0,0,"PLAYER ANGLE = " + PLAYER_ANGLE ;"Write the string 'PLAYER ANGLE = ' followed by the number held in PLAYER_ANGLE"
Text 0,20,"PLAYER SPEED = " + PLAYER_SPEED
Text 0,40,PLAYER_ANGLE + " / 5 = " + PLAYER_ANGLE/5
Text 0,60,"SHIPFRAME = " + game_player_frame
Text 0,80,"CO-ORDS = " + Int(PLAYER_X)
Text 140,80," , "
Text 160,80,Int(PLAYER_Y)
End If
;just like in "menu_draw_update()", the user can press a key which just makes the value of "FLAG_SCREENSAVE" equal 1.
;when the code gets to here, it saves out the named Buffer as a BMP picture.
If FLAG_SAVESCREEN=1 Then
SaveBuffer (BackBuffer(),"CRGameScreen.bmp")
FLAG_SAVESCREEN = 0
End If
Flip ;as before in "menu_draw_update()", FLIP everything we've just drawn on the backbuffer and show it on the frontbuffer, i.e.: your monitor!!
End Function
;a little function which randomizes the x and y coordinates of each version of the "stars" Type, plus it's "depth" property
Function game_stars_randomize()
For star.stars=Each stars
star\x=Rnd(-5,SCREEN_WIDTH) ;create random x and y positions for all the stars
star\y=Rnd(-5,SCREEN_HEIGHT)
star\depth=Rnd(1,5) ;the depth of the stars results in our sexy parallex effect
Next
End Function
;an even littler function which just gives us random x and y coordinates for the player.